﻿using Common;
using NursingFormSystem.Common;
using NursingFormSystem.Model;
using NursingFormSystem.NurFormsService;
using SQLDLL;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace NursingFormSystem.TubeDrawing
{
    public partial class ExtubationRiskNursing : Form
    {
        //窗体构造函数
        public static Tb_User LoginUser;
        public Tb_User InitLoginUser(string[] UserParam)
        {
            if (LoginUser == null)
            {
                LoginUser = new Tb_User();
                LoginUser.UserId = UserParam[0];
                LoginUser.UserName = UserParam[1];
                LoginUser.DepartmentCode = UserParam[2];
                LoginUser.DepartmentName = UserParam[3];
                LoginUser.JobTitle = UserParam[4];
                LoginUser.PositionTitle = UserParam[5];
            }
            return LoginUser;
        }

        DataTable dt = null;
        public NurFormsService.NursingForm formService = new NurFormsService.NursingForm();
        NursingFormRecord record = new NursingFormRecord();
        public WebReference2.FunctionAndPermissions WebScale = new WebReference2.FunctionAndPermissions();
        public int Sum = 0;
        string[] user;
        string[] patientinfo;
        string formName = "";
        string formID = "";
        string esSwitch = Base.ESSwitch;//获取是否使用电签标识

        public ExtubationRiskNursing(string[] UserParm, string[] PatientInfo, string FormName, string FormID)
        {
            InitializeComponent();
            InitLoginUser(UserParm);

            user = UserParm;
            patientinfo = PatientInfo;        
        }

        //保存
        private void simpleButtonbaocun_Click(object sender, EventArgs e)
        {
            #region
            Extubation bg = new Extubation();
            //评估日期
            bg.PingGuRiQi = dateEditpingguriqi.DateTime.ToString("yyyy-MM-dd HH:mm:ss");
            bg.NianLin = radioGroupnianling.EditValue + "";       //年龄
            bg.YiShi = radioGroupyishi.EditValue + "";           //意识
            bg.QingXu = radioGroupqingxu.EditValue + "";         //情绪
            bg.HuoDong = radioGrouphuodong.EditValue + "";       //活动  
            bg.TengTong = radioGrouptengtong.EditValue + "";     //疼痛
            bg.GouTong = radioGroupgoutong.EditValue + "";       //沟通
            //高危-气管
            int GaoWeiqiguan = 0;
            if (numericUpDownqiguan.Text == "")
                GaoWeiqiguan = 1;
            else
                GaoWeiqiguan = Convert.ToInt32(numericUpDownqiguan.Text);
            //
            int GaoWeixiaongdao = 0;
            if (numericUpDownxiongdao.Text == "")
                GaoWeixiaongdao = 1;
            else
                GaoWeixiaongdao = Convert.ToInt32(numericUpDownxiongdao.Text);
            //
            int GaoWeixingqiang = 0;
            if (numericUpDownxiongqiang.Text == "")
                GaoWeixingqiang = 1;
            else
                GaoWeixingqiang = Convert.ToInt32(numericUpDownxiongqiang.Text);
            //
            int GaoWeixiongshi = 0;
            if (numericUpDownnaoshi.Text == "")
                GaoWeixiongshi = 1;
            else
                GaoWeixiongshi = Convert.ToInt32(numericUpDownnaoshi.Text);
            //
            int GaoWeiqianlian = 0;
            if (numericUpDownqianlei.Text == "")
                GaoWeiqianlian = 1;
            else
                GaoWeiqianlian = Convert.ToInt32(numericUpDownqianlei.Text);
            //
            int GaoWeiwenhe = 0;
            if (numericUpDownwenhe.Text == "")
                GaoWeiwenhe = 1;
            else
                GaoWeiwenhe = Convert.ToInt32(numericUpDownwenhe.Text);
            //
            int GaoWeiqita = 0;
            if (numericUpDownqitag.Text == "")
                GaoWeiqita = 1;
            else
                GaoWeiqita = Convert.ToInt32(numericUpDownqitag.Text);

            //管道种类--高危
            bg.GDZL_GaoWei = (checkEditqiguan.Checked == true ? (GaoWeiqiguan * 3).ToString() : "0") + "#" + (checkEditxiaongdao.Checked == true ? (GaoWeixiaongdao * 3).ToString() : "0") + "#" + (checkEditxiaongqiang.Checked == true ? (GaoWeixingqiang * 3).ToString() : "0") + "#" +
                            (checkEditnaoshi.Checked == true ? (GaoWeixiongshi * 3).ToString() : "0") + "#" + (checkEditqianlian.Checked == true ? (GaoWeiqianlian * 3).ToString() : "0") + "#" + (checkEditwenhe.Checked == true ? (GaoWeiwenhe * 3).ToString() : "0") + "#" +
                            (checkEditaita.Checked == true ? (GaoWeiqita * 3).ToString() : "0");

            //
            int GaoWeiTguan = 0;
            if (numericUpDownTguan.Text == "")
                GaoWeiTguan = 1;
            else
                GaoWeiTguan = Convert.ToInt32(numericUpDownTguan.Text);
            //
            int GaoWeiweichang = 0;
            if (numericUpDownweichjang.Text == "")
                GaoWeiweichang = 1;
            else
                GaoWeiweichang = Convert.ToInt32(numericUpDownweichjang.Text);
            //
            int GaoWeishenjing = 0;
            if (numericUpDownshenjing.Text == "")
                GaoWeishenjing = 1;
            else
                GaoWeishenjing = Convert.ToInt32(numericUpDownshenjing.Text);
            //
            int GaoWeipicc = 0;
            if (numericUpDownpicc.Text == "")
                GaoWeipicc = 1;
            else
                GaoWeipicc = Convert.ToInt32(numericUpDownpicc.Text);
            //
            int GaoWeishangkou = 0;
            if (numericUpDownshangkou.Text == "")
                GaoWeishangkou = 1;
            else
                GaoWeishangkou = Convert.ToInt32(numericUpDownshangkou.Text);
            //
            int GaoWeiqitaz = 0;
            if (numericUpDownqitaz.Text == "")
                GaoWeiqitaz = 1;
            else
                GaoWeiqitaz = Convert.ToInt32(numericUpDownqitaz.Text);

            //管道种类--中危
            bg.GDZL_ZhongWei = (checkEdittg.Checked == true ? (GaoWeiTguan * 2).ToString() : "0") + "#" + (checkEditweichang.Checked == true ? (GaoWeiweichang * 2).ToString() : "0") + "#" + (checkEditshenjing.Checked == true ? (GaoWeishenjing * 2).ToString() : "0") + "#" +
                            (checkEdit1picc.Checked == true ? (GaoWeipicc * 2).ToString() : "0") + "#" + (checkEdit1shanggan.Checked == true ? (GaoWeishangkou * 2).ToString() : "0") + "#" + (checkEdit1qitaz.Checked == true ? (GaoWeiqitaz * 2).ToString() : "0");

            //
            int GaoWeidaoniao = 0;
            if (numericUpDowndaoniao.Text == "")
                GaoWeidaoniao = 1;
            else
                GaoWeidaoniao = Convert.ToInt32(numericUpDowndaoniao.Text);
            //
            int GaoWeiweiguan = 0;
            if (numericUpDownweiguan.Text == "")
                GaoWeiweiguan = 1;
            else
                GaoWeiweiguan = Convert.ToInt32(numericUpDownweiguan.Text);
            //
            int GaoWeiqitad = 0;
            if (numericUpDownqytad.Text == "")
                GaoWeiqitad = 1;
            else
                GaoWeiqitad = Convert.ToInt32(numericUpDownqytad.Text);

            //管道种类--低危
            bg.GDZL_DiWei = (checkEditdaoniao.Checked == true ? (GaoWeidaoniao * 1).ToString() : "0") + "#" + (checkEditweiguan.Checked == true ? (GaoWeiweiguan * 1).ToString() : "0") + "#" + (checkEditqitaguan.Checked == true ? (GaoWeiqitad * 1).ToString() : "0");

            //管道种类--文本
            bg.GDZL_GaoWei_Text = (numericUpDownqiguan.Text) + "/" + (numericUpDownxiongdao.Text) + "/" + (numericUpDownxiongqiang.Text) + "/" + (numericUpDownnaoshi.Text) + "/" + (numericUpDownqianlei.Text)+ "/" + (numericUpDownwenhe.Text) + "/" +  (numericUpDownqitag.Text);            
            bg.GDZL_ZhongWei_Text = (numericUpDownTguan.Text) + "/" + (numericUpDownweichjang.Text) + "/" + (numericUpDownshenjing.Text) + "/" + (numericUpDownpicc.Text) + "/" + (numericUpDownshangkou.Text) + "/" + (numericUpDownqitaz.Text);
            bg.GDZL_DiWei_Text = (numericUpDowndaoniao.Text)  + "/" + (numericUpDownweiguan.Text)  + "/" + (numericUpDownqytad.Text);

            //护理措施
            bg.HuLiCuoShi = (checkEditppinggu.Checked == true ? "1" : "0") + "#" + (checkEditguandao.Checked == true ? "1" : "0") + "#" + (checkEditzuohao.Checked == true ? "1" : "0") + "#" +
                            (checkEditjiyu.Checked == true ? "1" : "0") + "#" + (checkEditshishi.Checked == true ? "1" : "0") + "#" + (checkEditduiwai.Checked == true ? "1" : "0") + "#" +
                            (checkEditjishi.Checked == true ? "1" : "0") + "#" + (checkEditgaozhi.Checked == true ? "1" : "0") + "#" + (checkEditqita.Checked == true ? "1" : "0");
            bg.ZheRenHuShiQianMing = textzerenhushiqianming.Text;      //责任护士签字
            //总分
            bg.ZongFen = textzongfen.Text;
            //表单ID
            bg.FormId = (int)FormType.Extubation;
            //表单名字
            bg.FormName = EnumHelper.GetDescription(FormType.Extubation);
            bg.HuanZheQianMing = textEdithzjsqz.Text;             //患者/家属签字
            bg.YuHuanZheGuanXi = comboBoxEdityhzgx.Text;         //与患者关系
            bg.YuFangXiaoGuo = radioGroupyfxg.EditValue + "";    //预防效果  

            record.NursingFormData = XmlUtil.ObjectToXML(bg, Encoding.UTF8);
            //表单ID
            record.FormId = (int)FormType.Extubation;
            //表单名字
            record.FormName = EnumHelper.GetDescription(FormType.Extubation);

            //住院号
            record.PatientId = patientinfo[0];
            //住院次数
            record.VisitId = Convert.ToInt32(patientinfo[1]);
            //患者姓名
            record.PatientName = patientinfo[2];
            //床号
            record.BedNo = patientinfo[5];
            //当前患者科室ID
            record.DepartmentId = patientinfo[8];
            //当前患者科室名称
            record.DepartmentName = patientinfo[9];
            //当前患者病区ID
            record.AreaId = patientinfo[10];
            //当前患者病区名称
            record.AreaName = patientinfo[11];
            //时间
            record.AssessmentDate = dateEditpingguriqi.DateTime;

            var ret2 = formService.SetNursingFormRecord(Newtonsoft.Json.JsonConvert.SerializeObject(record));
            if (ret2.S == true)
            {
                //MessageBox.Show(ret2.M);
                //保存字段拼接成xml格式
                string signXml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><pingguriqi name=\"评估日期\">" + dateEditpingguriqi.Text + "</pingguriqi><zongfen name=\"总分\">" + textzongfen.Text + "</zongfen>"
                                 + "<nianling name=\"年龄\">" + radioGroupnianling.Text + "</nianling><yishi name=\"意识\">" + radioGroupyishi.Text + "</yishi><huodong name=\"活动\">" + radioGrouphuodong.Text + "</huodong>"
                                 + "<qingxu name=\"情绪\">" + radioGroupqingxu.Text + "</qingxu><tengtong name=\"疼痛\">" + radioGrouptengtong.Text + "</tengtong><goutong name=\"沟通\">" + radioGroupgoutong.Text + "</goutong>"
                                 + "<hulicuoshi name=\"护理措施\">" + (checkEditppinggu.Checked == true ? "1" : "0") + "#" + (checkEditguandao.Checked == true ? "1" : "0") + "#" + (checkEditzuohao.Checked == true ? "1" : "0") + "#" + (checkEditjiyu.Checked == true ? "1" : "0") + "#" + (checkEditduiwai.Checked == true ? "1" : "0") + "#" + (checkEditshishi.Checked == true ? "1" : "0") + "#" + (checkEditjishi.Checked == true ? "1" : "0") + "#" + (checkEditgaozhi.Checked == true ? "1" : "0") + "#" + (checkEditqita.Checked == true ? "1" : "0") + "</hulicuoshi>"
                                 + "<zenrenhushiqianzi name=\"责任护士签字\">" + textzerenhushiqianming.Text + "</zenrenhushiqianzi><huozhejishuqianzi name=\"患者家属签字\">" + textEdithzjsqz.Text + "</huozhejishuqianzi><yuhuanzheguanxi name=\"年龄\">" + comboBoxEdityhzgx.Text + "</yuhuanzheguanxi><yufangxiaoguo name=\"预防效果\">" + radioGroupyfxg.Text + "</yufangxiaoguo>"
                                 + "<guandaozhongleigaowei name=\"管道种类高危\">" + (checkEditqiguan.Checked == true ? "1" : "0") + "#" + (checkEditxiaongdao.Checked == true ? "1" : "0") + "#" + (checkEditxiaongqiang.Checked == true ? "1" : "0") + "#" + (checkEditnaoshi.Checked == true ? "1" : "0") + "#" + (checkEditqianlian.Checked == true ? "1" : "0") + "#" + (checkEditwenhe.Checked == true ? "1" : "0") + "#" + (checkEditaita.Checked == true ? "1" : "0") + "</zenrenhushiqianzi>"
                                 + "<gaowei1 name=\"气管导致\">" + numericUpDownqiguan.Text + "</gaowei1><gaowei2 name=\"胸导管\">" + numericUpDownxiongdao.Text + "</gaowei2><gaowei3 name=\"胸腔\">" + numericUpDownxiongqiang.Text + "</gaowei3>"
                                 + "<gaowei4 name=\"脑室\">" + numericUpDownnaoshi.Text + "</gaowei4><gaowei5 name=\"前列腺\">" + numericUpDownqianlei.Text + "</gaowei5><gaowei6 name=\"吻合\">" + numericUpDownwenhe.Text + "</gaowei6><gaowei7 name=\"高危其他\">" + numericUpDownqitag.Text + "</gaowei7>"
                                 + "<guandaozhongleizhongwei name=\"管道种类中危\">" + (checkEdittg.Checked == true ? "1" : "0") + "#" + (checkEditweichang.Checked == true ? "1" : "0") + "#" + (checkEditshenjing.Checked == true ? "1" : "0") + "#" + (checkEdit1picc.Checked == true ? "1" : "0") + "#" + (checkEdit1shanggan.Checked == true ? "1" : "0") + "#" + (checkEdit1qitaz.Checked == true ? "1" : "0") + "</guandaozhongleizhongwei>"
                                 + "<zhongwei1 name=\"T管\">" + numericUpDownTguan.Text + "</zhongwei1><zhongwei2 name=\"胃肠\">" + numericUpDownweichjang.Text + "</zhongwei2><zhongwei3 name=\"深静\">" + numericUpDownshenjing.Text + "</zhongwei3><zhongwei4 name=\"picc\">" + numericUpDownpicc.Text + "</zhongwei4><zhongwei5 name=\"伤口\">" + numericUpDownshangkou.Text + "</zhongwei5><zhongwei6 name=\"中危其他\">" + numericUpDownqitaz.Text + "</zhongwei6>"
                                 + "<guandaozhongleidiwei name=\"T管道种类低危\">" + (checkEditdaoniao.Checked == true ? "1" : "0") + "#" + (checkEditweiguan.Checked == true ? "1" : "0") + "#" + (checkEditqitaguan.Checked == true ? "1" : "0") + "</guandaozhongleidiwei>"
                                 + "<diwei1 name=\"导尿\">" + numericUpDowndaoniao.Text + "</diwei1><diwei2 name=\"胃管\">" + numericUpDownweiguan.Text + "</diwei2><diwei3 name=\"低危其他\">" + numericUpDownqytad.Text + "</diwei3>";
                //TODO:电签接口提交
                //string extraInfo = "<?xml version=\"1.0\" encoding=\"UTF-16\"?><root><sign_sys>业务系统名称</sign_sys><title>单据名称</title><patient_id>病人ID</patient_id><patient_name>病人姓名</patient_name><emr_id>电子病历ID</emr_id><emr_catalog>电子病历类型</emr_catalog><his_id>HIS ID</his_id><event_no>住院号或门诊号</event_no><visit_number>住院次数，0次为门诊病人</visit_number><dept_name>科室名称</dept_name><prescribe_number>医嘱号或门诊号</prescribe_number><prescribe_sub_number>医嘱子序号或门诊子序号</prescribe_sub_number><prescribe_operation>医嘱操作（发送、校对、停止、作废）或门诊处方操作（发送）</prescribe_operation><radiotherapy_id>放疗号</radiotherapy_id><process_name>CT定位申请单审核</process_name><process_time>CT定位申请单审核时间</process_time><extend_value_1>备用扩展1</extend_value_1><extend_value_2>备用扩展2</extend_value_2><extend_value_3>备用扩展3</extend_value_3><extend_value_4>备用扩展4</extend_value_4><extend_value_5>备用扩展5</extend_value_5><extend_value_6>备用扩展6</extend_value_6><extend_value_7>备用扩展7</extend_value_7><extend_value_8>备用扩展8</extend_value_8><extend_value_9>备用扩展9</extend_value_9></root>";
                //ElectronicSignature es = new ElectronicSignature(LoginUser);
                //es.GetElectronicSignatureImage(es, signXml, extraInfo, formID, formName, patientinfo[0], int.Parse(patientinfo[1]));
                //MessageBox.Show(ret2.M);
                //string extraInfo = "<?xml version=\"1.0\" encoding=\"UTF-16\"?><root><sign_sys>业务系统名称</sign_sys><title>单据名称</title><patient_id>病人ID</patient_id><patient_name>病人姓名</patient_name><emr_id>电子病历ID</emr_id><emr_catalog>电子病历类型</emr_catalog><his_id>HIS ID</his_id><event_no>住院号或门诊号</event_no><visit_number>住院次数，0次为门诊病人</visit_number><dept_name>科室名称</dept_name><prescribe_number>医嘱号或门诊号</prescribe_number><prescribe_sub_number>医嘱子序号或门诊子序号</prescribe_sub_number><prescribe_operation>医嘱操作（发送、校对、停止、作废）或门诊处方操作（发送）</prescribe_operation><radiotherapy_id>放疗号</radiotherapy_id><process_name>CT定位申请单审核</process_name><process_time>CT定位申请单审核时间</process_time><extend_value_1>备用扩展1</extend_value_1><extend_value_2>备用扩展2</extend_value_2><extend_value_3>备用扩展3</extend_value_3><extend_value_4>备用扩展4</extend_value_4><extend_value_5>备用扩展5</extend_value_5><extend_value_6>备用扩展6</extend_value_6><extend_value_7>备用扩展7</extend_value_7><extend_value_8>备用扩展8</extend_value_8><extend_value_9>备用扩展9</extend_value_9></root>";
                //ElectronicSignature es = new ElectronicSignature(LoginUser);
                //es.GetElectronicSignatureImage(es, signXml, extraInfo, formID, formName, patientinfo[0], int.Parse(patientinfo[1]));
                MessageBox.Show(ret2.M);
            }
            else
            {
                MessageBox.Show(ret2.M);
            }
            #endregion
        }

        //计算总分
        #region
        public void SunTotal()
        {
            int Total = 0;
            int Total1 = 0;
            int Total2 = 0;
            int Total3 = 0;
            int Total4 = 0;
            int Total5 = 0;
            int Total6 = 0;
            int Total7 = 0;
            int Total8 = 0;
            int Total9 = 0;
            int Total10 = 0;
            int Total11 = 0;
            int Total12 = 0;
            int Total13 = 0;
            int Total14 = 0;
            int Total15 = 0;
            int Total16 = 0;
            int Total17 = 0;
            int Total18 = 0;
            int Total19 = 0;
            int Total20 = 0;
            int Total21 = 0;

            //年龄
            if (radioGroupnianling.SelectedIndex == 0)
                Total = 2;
            else if (radioGroupnianling.SelectedIndex == 1)
                Total = 2;
            else
                Total = 0;
            //意识
            if (radioGroupyishi.SelectedIndex == 0)
                Total1 = 3;
            else if (radioGroupyishi.SelectedIndex == 1)
                Total1 = 2;
            else if (radioGroupyishi.SelectedIndex == 2)
                Total1 = 1;
            else
                Total1 = 0;
            //情绪
            if (radioGroupqingxu.SelectedIndex == 0)
                Total2 = 3;
            else if (radioGroupqingxu.SelectedIndex == 1)
                Total2 = 2;
            else if (radioGroupqingxu.SelectedIndex == 2)
                Total2 = 1;
            else
                Total2 = 0;
            //活动
            if (radioGrouphuodong.SelectedIndex == 0)
                Total3 = 3;
            else if (radioGrouphuodong.SelectedIndex == 1)
                Total3 = 2;
            else if (radioGrouphuodong.SelectedIndex == 2)
                Total3 = 2;
            else if (radioGrouphuodong.SelectedIndex == 3)
                Total3 = 2;
            else if (radioGrouphuodong.SelectedIndex == 4)
                Total3 = 1;
            else
                Total3 = 0;
            //疼痛
            if (radioGrouptengtong.SelectedIndex == 0)
                Total4 = 3;
            else if (radioGrouptengtong.SelectedIndex == 1)
                Total4 = 1;
            else
                Total4 = 0;
            //沟通
            if (radioGroupgoutong.SelectedIndex == 0)
                Total5 = 3;
            else if (radioGroupgoutong.SelectedIndex == 1)
                Total5 = 1;
            else
                Total5 = 0;
            //高危-气管
            if (checkEditqiguan.Checked == true)
            {
                if (numericUpDownqiguan.Text == "")
                    Total6 = 3;
                else
                    Total6 = Convert.ToInt32(numericUpDownqiguan.Text) * 3;
            }
            else
                Total6 = 0;
            //高危-胸导
            if (checkEditxiaongdao.Checked == true)
            {
                if (numericUpDownxiongdao.Text == "")
                    Total7 = 3;
                else
                    Total7 = Convert.ToInt32(numericUpDownxiongdao.Text) * 3;
            }
            else
                Total7 = 0;
            //高危-胸腔
            if (checkEditxiaongqiang.Checked == true)
            {
                if (numericUpDownxiongqiang.Text == "")
                    Total8 = 3;
                else
                    Total8 = Convert.ToInt32(numericUpDownxiongqiang.Text) * 3;
            }
            else
                Total8 = 0;
            //高危-脑室
            if (checkEditnaoshi.Checked == true)
            {
                if (numericUpDownnaoshi.Text == "")
                    Total9 = 3;
                else
                    Total9 = Convert.ToInt32(numericUpDownnaoshi.Text) * 3;
            }
            else
                Total9 = 0;
            //高危-前列
            if (checkEditqianlian.Checked == true)
            {
                if (numericUpDownqianlei.Text == "")
                    Total10 = 3;
                else
                    Total10 = Convert.ToInt32(numericUpDownqianlei.Text) * 3;
            }
            else
                Total10 = 0;
            //高危-吻合
            if (checkEditwenhe.Checked == true)
            {
                if (numericUpDownwenhe.Text == "")
                    Total11 = 3;
                else
                    Total11 = Convert.ToInt32(numericUpDownwenhe.Text) * 3;
            }
            else
                Total11 = 0;
            //高危-其他
            if (checkEditaita.Checked == true)
            {
                if (numericUpDownqitag.Text == "")
                    Total12 = 3;
                else
                    Total12 = Convert.ToInt32(numericUpDownqitag.Text) * 3;
            }
            else
                Total12 = 0;
            //中危-T管
            if (checkEdittg.Checked == true)
            {
                if (numericUpDownTguan.Text == "")
                    Total13 = 2;
                else
                    Total13 = Convert.ToInt32(numericUpDownTguan.Text) * 2;
            }
            else
                Total13 = 0;
            //中危-胃肠
            if (checkEditweichang.Checked == true)
            {
                if (numericUpDownweichjang.Text == "")
                    Total14 = 2;
                else
                    Total14 = Convert.ToInt32(numericUpDownweichjang.Text) * 2;
            }
            else
                Total14 = 0;
            //中危-深静
            if (checkEditshenjing.Checked == true)
            {
                if (numericUpDownshenjing.Text == "")
                    Total15 = 2;
                else
                    Total15 = Convert.ToInt32(numericUpDownshenjing.Text) * 2;
            }
            else
                Total15 = 0;
            //中危-picc
            if (checkEdit1picc.Checked == true)
            {
                if (numericUpDownpicc.Text == "")
                    Total16 = 2;
                else
                    Total16 = Convert.ToInt32(numericUpDownpicc.Text) * 2;
            }
            else
                Total16 = 0;
            //中危-伤口
            if (checkEdit1shanggan.Checked == true)
            {
                if (numericUpDownshangkou.Text == "")
                    Total17 = 2;
                else
                    Total17 = Convert.ToInt32(numericUpDownshangkou.Text) * 2;
            }
            else
                Total17 = 0;
            //中危-其他
            if (checkEdit1qitaz.Checked == true)
            {
                if (numericUpDownqitaz.Text == "")
                    Total18 = 2;
                else
                    Total18 = Convert.ToInt32(numericUpDownqitaz.Text) * 2;
            }
            else
                Total18 = 0;
            //低危-导尿
            if (checkEditdaoniao.Checked == true)
            {
                if (numericUpDowndaoniao.Text == "")
                    Total19 = 1;
                else
                    Total19 = Convert.ToInt32(numericUpDowndaoniao.Text) * 1;
            }
            else
                Total19 = 0;
            //低危-胃管
            if (checkEditweiguan.Checked == true)
            {
                if (numericUpDownweiguan.Text == "")
                    Total20 = 1;
                else
                    Total20 = Convert.ToInt32(numericUpDownweiguan.Text) * 1;
            }
            else
                Total20 = 0;
            //低危-其他
            if (checkEditqitaguan.Checked == true)
            {
                if (numericUpDownqytad.Text == "")
                    Total21 = 1;
                else
                    Total21 = Convert.ToInt32(numericUpDownqytad.Text) * 1;
            }
            else
                Total21 = 0;


            Sum = Total + Total1 + Total2 + Total3 + Total4 + Total5 + Total6 + Total7 + Total8 + Total9 + Total10 + Total11 + Total12 + Total13 + Total14 + Total15 + Total16 + Total17 + Total18 + Total19 + Total20 + Total21;
            textzongfen.Text = Sum.ToString();

        }
        #endregion
        private void ExtubationRiskNursing_Load(object sender, EventArgs e)
        {

            dateEditpingguriqi.DateTime = DateTime.Now;
            textzongfen.Text = "";    //默认总分为0
            radioGroupnianling.SelectedIndex = -1;
            radioGroupyishi.SelectedIndex = -1;
            radioGroupqingxu.SelectedIndex = -1;
            radioGrouphuodong.SelectedIndex = -1;
            radioGrouptengtong.SelectedIndex = -1;
            radioGroupgoutong.SelectedIndex = -1;

        }

        //引用计算分数
        private void radioGroupnianling_SelectedIndexChanged(object sender, EventArgs e)    
        {
            SunTotal();
        }
        //查询
        private void simpleButtonchaxun_Click(object sender, EventArgs e)
        {
            #region
            Extubation bg = new Extubation();
            //住院号
            record.PatientId = patientinfo[0];
            //住院次数
            record.VisitId = Convert.ToInt32(patientinfo[1]);
            //患者姓名
            record.PatientName = patientinfo[2];
            //床号
            record.BedNo = patientinfo[5];
            //当前患者科室ID
            record.DepartmentId = patientinfo[8];
            //当前患者科室名称
            record.DepartmentName = patientinfo[9];
            //当前患者病区ID
            record.AreaId = patientinfo[10];
            //当前患者病区名称
            record.AreaName = patientinfo[11];

            var ret = formService.GetNursingFormRecordByDate(patientinfo[0], Convert.ToInt32(patientinfo[1]), (int)FormType.Extubation, dateEditpingguriqi.DateTime, dateEditpingguriqi.DateTime);

            if (ret.Code == 1)
            {
                List<NursingFormRecord> list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<NursingFormRecord>>(ret.D);
                if(list.Count>0)
                {
                    NursingFormRecord record1 = list[0];
                    bg = XmlUtil.XMLToObject<Extubation>(record1.NursingFormData, Encoding.UTF8);

                    var begin = dateEditpingguriqi.DateTime.ToString("yyyy-MM-dd 00:00:00");
                    var end = dateEditpingguriqi.DateTime.ToString("yyyy-MM-dd 23:59:59");
                    // var bg = tb.BaGuanList.Where(x => String.Compare(x.PingGuRiQi, begin) >= 0 && String.Compare(x.PingGuRiQi, end)<=0).OrderByDescending(x=>x.PingGuRiQi).FirstOrDefault();
                    //年龄
                    radioGroupnianling.SelectedIndex = Convert.ToInt32(bg.NianLin == "" ? "-1" : bg.NianLin);
                    //意识
                    radioGroupyishi.SelectedIndex = Convert.ToInt32(bg.YiShi == "" ? "-1" : bg.YiShi);
                    //情绪
                    radioGroupqingxu.SelectedIndex = Convert.ToInt32(bg.QingXu == "" ? "-1" : bg.QingXu);
                    //活动
                    radioGrouphuodong.SelectedIndex = Convert.ToInt32(bg.HuoDong == "" ? "-1" : bg.HuoDong);
                    //疼痛
                    radioGrouptengtong.SelectedIndex = Convert.ToInt32(bg.TengTong == "" ? "-1" : bg.TengTong);
                    //沟通
                    radioGroupgoutong.SelectedIndex = Convert.ToInt32(bg.GouTong == "" ? "-1" : bg.GouTong);
                    //总分
                    textzongfen.Text = bg.ZongFen;
                    //评估日期
                    dateEditpingguriqi.Text = bg.PingGuRiQi;
                    
                    //管道种类--高危--气管
                    var qiguan = bg.GDZL_GaoWei.Split('#');
                    if (qiguan[0] == "0")
                        checkEditqiguan.Checked = false;
                    else
                        checkEditqiguan.Checked = true;

                    //管道种类--高危--胸导
                    var xiaongdao = bg.GDZL_GaoWei.Split('#');
                    if (xiaongdao[1] == "0")
                        checkEditxiaongdao.Checked = false;
                    else
                        checkEditxiaongdao.Checked = true;
                    //管道种类--高危--胸腔
                    var xioangqiang = bg.GDZL_GaoWei.Split('#');
                    if (xioangqiang[2] == "0")
                        checkEditxiaongqiang.Checked = false;
                    else
                        checkEditxiaongqiang.Checked = true;
                    //管道种类--高危--脑室
                    var naoshi = bg.GDZL_GaoWei.Split('#');
                    if (naoshi[3] == "0")
                        checkEditnaoshi.Checked = false;
                    else
                        checkEditnaoshi.Checked = true;
                    //管道种类--高危--前列
                    var qianlei = bg.GDZL_GaoWei.Split('#');
                    if (qianlei[4] == "0")
                        checkEditqianlian.Checked = false;
                    else
                        checkEditqianlian.Checked = true;
                    //管道种类--高危--吻合
                    var wenhe = bg.GDZL_GaoWei.Split('#');
                    if (wenhe[5] == "0")
                        checkEditwenhe.Checked = false;
                    else
                        checkEditwenhe.Checked = true;
                    //管道种类--高危--其他
                    var qitag = bg.GDZL_GaoWei.Split('#');
                    if (qitag[6] == "0")
                        checkEditaita.Checked = false;
                    else
                        checkEditaita.Checked = true;

                    //管道种类--中危--T管
                    var tguan = bg.GDZL_ZhongWei.Split('#');
                    if (tguan[0] == "0")
                        checkEdittg.Checked = false;
                    else
                        checkEdittg.Checked = true;
                    //管道种类--中危--胃肠
                    var weichang = bg.GDZL_ZhongWei.Split('#');
                    if (weichang[1] == "0")
                        checkEditweichang.Checked = false;
                    else
                        checkEditweichang.Checked = true;
                    //管道种类--中危--深静
                    var shenjing = bg.GDZL_ZhongWei.Split('#');
                    if (shenjing[2] == "0")
                        checkEditshenjing.Checked = false;
                    else
                        checkEditshenjing.Checked = true;
                    //管道种类--中危--picc
                    var pic = bg.GDZL_ZhongWei.Split('#');
                    if (pic[3] == "0")
                        checkEdit1picc.Checked = false;
                    else
                        checkEdit1picc.Checked = true;
                    //管道种类--中危--伤口
                    var shangkoui = bg.GDZL_ZhongWei.Split('#');
                    if (shangkoui[4] == "0")
                        checkEdit1shanggan.Checked = false;
                    else
                        checkEdit1shanggan.Checked = true;
                    //管道种类--中危--其他
                    var qitaz = bg.GDZL_ZhongWei.Split('#');
                    if (qitaz[5] == "0")
                        checkEdit1qitaz.Checked = false;
                    else
                        checkEdit1qitaz.Checked = true;

                    //管道种类--低危--导尿
                    var daoniao = bg.GDZL_DiWei.Split('#');
                    if (daoniao[0] == "0")
                        checkEditdaoniao.Checked = false;
                    else
                        checkEditdaoniao.Checked = true;
                    //管道种类--低危--胃管
                    var weiguan = bg.GDZL_DiWei.Split('#');
                    if (weiguan[1] == "0")
                        checkEditweiguan.Checked = false;
                    else
                        checkEditweiguan.Checked = true;
                    //管道种类--低危--其他
                    var qitad = bg.GDZL_DiWei.Split('#');
                    if (qitad[2] == "0")
                        checkEditqitaguan.Checked = false;
                    else
                        checkEditqitaguan.Checked = true;

                    //护理措施--评估
                    var pinggu = bg.HuLiCuoShi.Split('#');
                    if (pinggu[0] == "1")
                        checkEditppinggu.Checked = true;
                    else
                        checkEditppinggu.Checked = false;
                    //护理措施--管道
                    var guandao = bg.HuLiCuoShi.Split('#');
                    if (guandao[1] == "1")
                        checkEditguandao.Checked = true;
                    else
                        checkEditguandao.Checked = false;
                    //护理措施--做好
                    var zuohao = bg.HuLiCuoShi.Split('#');
                    if (zuohao[2] == "1")
                        checkEditzuohao.Checked = true;
                    else
                        checkEditzuohao.Checked = false;
                    //护理措施--给予
                    var jiyu = bg.HuLiCuoShi.Split('#');
                    if (jiyu[3] == "1")
                        checkEditjiyu.Checked = true;
                    else
                        checkEditjiyu.Checked = false;
                    //护理措施--实施
                    var shishi = bg.HuLiCuoShi.Split('#');
                    if (shishi[4] == "1")
                        checkEditshishi.Checked = true;
                    else
                        checkEditshishi.Checked = false;
                    //护理措施--对外
                    var duiwai = bg.HuLiCuoShi.Split('#');
                    if (duiwai[5] == "1")
                        checkEditduiwai.Checked = true;
                    else
                        checkEditduiwai.Checked = false;                   
                    //护理措施--及时
                    var jishi = bg.HuLiCuoShi.Split('#');
                    if (jishi[6] == "1")
                        checkEditjishi.Checked = true;
                    else
                        checkEditjishi.Checked = false;
                    //护理措施--告知
                    var gaozhi = bg.HuLiCuoShi.Split('#');
                    if (gaozhi[7] == "1")
                        checkEditgaozhi.Checked = true;
                    else
                        checkEditgaozhi.Checked = false;
                    //护理措施--其他
                    var qita = bg.HuLiCuoShi.Split('#');
                    if (qita[8] == "1")
                        checkEditqita.Checked = true;
                    else
                        checkEditqita.Checked = false;
                    //责任护士签字
                    textzerenhushiqianming.Text = bg.ZheRenHuShiQianMing;
                    //患者/家属签名
                    textEdithzjsqz.Text = bg.HuanZheQianMing;
                    //与患者关系
                    comboBoxEdityhzgx.Text = bg.YuHuanZheGuanXi;
                    //预防效果
                    radioGroupyfxg.SelectedIndex = Convert.ToInt32(bg.YuFangXiaoGuo == "" ? "-1" : bg.YuFangXiaoGuo);
                    
                    //管道种类--文本                           

                    var guandaogaowei1 = bg.GDZL_GaoWei_Text.Split('/');
                    numericUpDownqiguan.Text = guandaogaowei1[0];

                    var guandaogaowei2 = bg.GDZL_GaoWei_Text.Split('/');
                    numericUpDownxiongdao.Text = guandaogaowei2[1];

                    var guandaogaowei3 = bg.GDZL_GaoWei_Text.Split('/');
                    numericUpDownxiongqiang.Text = guandaogaowei3[2];

                    var guandaogaowei4 = bg.GDZL_GaoWei_Text.Split('/');
                    numericUpDownnaoshi.Text = guandaogaowei4[3];

                    var guandaogaowei5 = bg.GDZL_GaoWei_Text.Split('/');
                    numericUpDownqianlei.Text = guandaogaowei5[4];

                    var guandaogaowei6 = bg.GDZL_GaoWei_Text.Split('/');
                    numericUpDownwenhe.Text = guandaogaowei6[5];

                    var guandaogaowei7 = bg.GDZL_GaoWei_Text.Split('/');
                    numericUpDownqitag.Text = guandaogaowei5[6];

                    var guandaozhongwei1 = bg.GDZL_GaoWei_Text.Split('/');
                    numericUpDownTguan.Text = guandaozhongwei1[0];

                    var guandaozhongwei2 = bg.GDZL_GaoWei_Text.Split('/');
                    numericUpDownweichjang.Text = guandaozhongwei2[1];

                    var guandaozhongwei3 = bg.GDZL_GaoWei_Text.Split('/');
                    numericUpDownshenjing.Text = guandaozhongwei3[2];

                    var guandaozhongwei4 = bg.GDZL_GaoWei_Text.Split('/');
                    numericUpDownpicc.Text = guandaozhongwei4[3];

                    var guandaozhongwei5 = bg.GDZL_GaoWei_Text.Split('/');
                    numericUpDownshangkou.Text = guandaozhongwei5[4];

                    var guandaozhongwei6 = bg.GDZL_GaoWei_Text.Split('/');
                    numericUpDownqitaz.Text = guandaozhongwei6[5];

                    var guandaodiwei1 = bg.GDZL_GaoWei_Text.Split('/');
                    numericUpDowndaoniao.Text = guandaodiwei1[0];

                    var guandaodiwei2 = bg.GDZL_GaoWei_Text.Split('/');
                    numericUpDownweiguan.Text = guandaodiwei2[1];

                    var guandaodiwei3 = bg.GDZL_GaoWei_Text.Split('/');
                    numericUpDownqytad.Text = guandaodiwei3[2];
                    
                }
                               
            }
            else if (ret.Code == 2)
            {
                //年龄
                radioGroupnianling.SelectedIndex = -1;
                //意识
                radioGroupyishi.SelectedIndex = -1;
                //情绪
                radioGroupqingxu.SelectedIndex = -1;
                //活动
                radioGrouphuodong.SelectedIndex = -1;
                //疼痛
                radioGrouptengtong.SelectedIndex = -1;
                //沟通
                radioGroupgoutong.SelectedIndex = -1;

                //管道种类--高危--气管
                    checkEditqiguan.Checked = false;

                //管道种类--高危--胸导
                    checkEditxiaongdao.Checked = false;

                //管道种类--高危--胸腔
                    checkEditxiaongqiang.Checked = false;
                
                //管道种类--高危--脑室
                    checkEditnaoshi.Checked = false;
                
                //管道种类--高危--前列
                    checkEditqianlian.Checked = false;
                
                //管道种类--高危--吻合
                    checkEditwenhe.Checked = false;
                
                //管道种类--高危--其他
                    checkEditaita.Checked = false;
            
                //管道种类--中危--T管
                    checkEdittg.Checked = false;
                
                //管道种类--中危--胃肠
                    checkEditweichang.Checked = false;
                
                //管道种类--中危--深静
                    checkEditshenjing.Checked = false;
                
                //管道种类--中危--picc
                    checkEdit1picc.Checked = false;
               
                //管道种类--中危--伤口
                    checkEdit1shanggan.Checked = false;
                
                //管道种类--中危--其他
                    checkEdit1qitaz.Checked = false;

                //管道种类--低危--导尿
                    checkEditdaoniao.Checked = false;
                
                //管道种类--低危--胃管
                    checkEditweiguan.Checked = false;
                
                //管道种类--低危--其他
                    checkEditqitaguan.Checked = false;
               
                //护理措施--评估
                    checkEditppinggu.Checked = false;
               
                //护理措施--管道
                    checkEditguandao.Checked = false;
               
                //护理措施--做好
                    checkEditzuohao.Checked = false;
                
                //护理措施--给予
                    checkEditjiyu.Checked = false;
               
                //护理措施--对外
                    checkEditduiwai.Checked = false;
               
                //护理措施--实施
                    checkEditshishi.Checked = false;
                
                //护理措施--及时
                    checkEditjishi.Checked = false;
                
                //护理措施--告知
                    checkEditgaozhi.Checked = false;
                
                //护理措施--其他
                    checkEditqita.Checked = false;
                
                //责任护士签字
                textzerenhushiqianming.Text = "";
                //患者/家属签名
                textEdithzjsqz.Text = "";
                //与患者关系
                comboBoxEdityhzgx.Text = "";
                //预防效果
                radioGroupyfxg.SelectedIndex = -1;

                 //管道种类--文本
                numericUpDownqiguan.Text = "";

                numericUpDownxiongdao.Text = "";

                numericUpDownxiongqiang.Text = "";

                numericUpDownnaoshi.Text = "";

                numericUpDownqianlei.Text = "";

                numericUpDownwenhe.Text = "";

                numericUpDownqitag.Text = "";

                numericUpDownTguan.Text = "";

                numericUpDownweichjang.Text = "";

                numericUpDownshenjing.Text = "";

                numericUpDownpicc.Text = "";

                numericUpDownshangkou.Text = "";

                numericUpDownqitaz.Text = "";

                numericUpDowndaoniao.Text = "";

                numericUpDownweiguan.Text = "";

                numericUpDownqytad.Text = "";               
            }
            else
            {
                MessageBox.Show(ret.M);
            }
            #endregion

        }
        //打印
        private void simpleButtondayin_Click(object sender, EventArgs e)
        {
            ExtubationRisPrint r = new ExtubationRisPrint(patientinfo[0], Convert.ToInt32(patientinfo[1]), (int)FormType.Extubation, dateEditpingguriqi.DateTime);
            r.Show();
        }

        //文本框的值计算
        private void numericUpDownceshi_ValueChanged(object sender, EventArgs e)  
        {
            SunTotal();
        }

        //管道种类文本框，默认0，勾选时值为1
        #region
        private void checkEditqiguan_CheckedChanged(object sender, EventArgs e)  
        {
            //气管
            if (checkEditqiguan.Checked == true)
                numericUpDownqiguan.Text = "1";
            else
                numericUpDownqiguan.Text = "";
            SunTotal();
        }

        private void checkEditxiaongdao_CheckedChanged(object sender, EventArgs e)
        {
            //胸导
            if (checkEditxiaongdao.Checked == true)
                numericUpDownxiongdao.Text = "1";
            else
                numericUpDownxiongdao.Text = "";
            SunTotal();
        }

        private void checkEditxiaongqiang_CheckedChanged(object sender, EventArgs e)
        {
            //胸腔
            if (checkEditxiaongqiang.Checked == true)
                numericUpDownxiongqiang.Text = "1";
            else
                numericUpDownxiongqiang.Text = "";
            SunTotal();
        }

        private void checkEditnaoshi_CheckedChanged(object sender, EventArgs e)
        {
            //脑室
            if (checkEditnaoshi.Checked == true)
                numericUpDownnaoshi.Text = "1";
            else
                numericUpDownnaoshi.Text = "";
            SunTotal();
        }

        private void checkEditqianlian_CheckedChanged(object sender, EventArgs e)
        {
            //前列
            if (checkEditqianlian.Checked == true)
                numericUpDownqianlei.Text = "1";
            else
                numericUpDownqianlei.Text = "";
            SunTotal();
        }

        private void checkEditwenhe_CheckedChanged(object sender, EventArgs e)
        {
            //吻合
            if (checkEditwenhe.Checked == true)
                numericUpDownwenhe.Text = "1";
            else
                numericUpDownwenhe.Text = "";
            SunTotal();
        }

        private void checkEditaita_CheckedChanged(object sender, EventArgs e)
        {
            //其他--高危
            if (checkEditaita.Checked == true)
                numericUpDownqitag.Text = "1";
            else
                numericUpDownqitag.Text = "";
            SunTotal();
        }

        private void checkEdittg_CheckedChanged(object sender, EventArgs e)
        {
            //T管
            if (checkEdittg.Checked == true)
                numericUpDownTguan.Text = "1";
            else
                numericUpDownTguan.Text = "";
            SunTotal();
        }

        private void checkEditweichang_CheckedChanged(object sender, EventArgs e)
        {
            //胃肠
            if (checkEditweichang.Checked == true)
                numericUpDownweichjang.Text = "1";
            else
                numericUpDownweichjang.Text = "";
            SunTotal();
        }

        private void checkEditshenjing_CheckedChanged(object sender, EventArgs e)
        {
            //深静
            if (checkEditshenjing.Checked == true)
                numericUpDownshenjing.Text = "1";
            else
                numericUpDownshenjing.Text = "";
            SunTotal();
        }

        private void checkEdit1picc_CheckedChanged(object sender, EventArgs e)
        {
            //picc
            if (checkEdit1picc.Checked == true)
                numericUpDownpicc.Text = "1";
            else
                numericUpDownpicc.Text = "";
            SunTotal();
        }

        private void checkEdit1shanggan_CheckedChanged(object sender, EventArgs e)
        {
            //伤口
            if (checkEdit1shanggan.Checked == true)
                numericUpDownshangkou.Text = "1";
            else
                numericUpDownshangkou.Text = "";
            SunTotal();
        }

        private void checkEdit1qitaz_CheckedChanged(object sender, EventArgs e)
        {
            //其他-中危
            if (checkEdit1qitaz.Checked == true)
                numericUpDownqitaz.Text = "1";
            else
                numericUpDownqitaz.Text = "";
            SunTotal();
        }

        private void checkEditdaoniao_CheckedChanged(object sender, EventArgs e)
        {
            //导尿
            if (checkEditdaoniao.Checked == true)
                numericUpDowndaoniao.Text = "1";
            else
                numericUpDowndaoniao.Text = "";
            SunTotal();
        }

        private void checkEditweiguan_CheckedChanged(object sender, EventArgs e)
        {
            //胃管
            if (checkEditweiguan.Checked == true)
                numericUpDownweiguan.Text = "1";
            else
                numericUpDownweiguan.Text = "";
            SunTotal();
        }

        private void checkEditqitaguan_CheckedChanged(object sender, EventArgs e)
        {
            //其他-低危
            if (checkEditqitaguan.Checked == true)
                numericUpDownqytad.Text = "1";
            else
                numericUpDownqytad.Text = "";
            SunTotal();
        }
        #endregion

        //历史记录
        private void simpleButtonlishijilu_Click(object sender, EventArgs e)
        {
            //ExtubationRiskNursingHistory ern = new ExtubationRiskNursingHistory(patientinfo, (int)FormType.PatientCare, dateEditpingguriqi.DateTime);
            //ern.ShowDialog();
        }


    }
}
        